<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">添加商铺</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">代理商名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[name]"
                                           value="" placeholder="请输入用户名" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">登录账号 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[login_name]"
                                           value="" placeholder="请输入用户名" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">登录密码 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="password" class="tpl-form-input" name="data[password]"
                                           value="" placeholder="请输入登录密码" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">确认密码 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="password" class="tpl-form-input" name="data[password_confirm]"
                                           value="" placeholder="请输入确认密码" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">联系人 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[contacts]"
                                           value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">联系电话 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[contacts_tel]"
                                           value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">代理商地址 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[address]"
                                           value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">省份 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="province" name="data[province]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择省份', maxHeight: 400}" onchange="regionSelect(this,'city')">
                                        <option value=""></option>
                                        <?php foreach ($region as $g): ?>
                                            <option value="<?=$g['id'] ?>"
                                                    lng="<?=$g['lng'] ?>"
                                                    lat="<?=$g['lat'] ?>"
                                            >
                                                <?=$g['name'] ?>
                                            </option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">城市 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="city" name="data[city]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择城市', maxHeight: 400}" onchange="regionSelect(this,'district')">
                                        <option value=""></option>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">区县 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="district" name="data[district]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择区县', maxHeight: 400}" onchange="regionSelect(this,'')">
                                        <option value=""></option>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">街道 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[town]"
                                           value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">坐标 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" id="lng" name="data[lng]"
                                           value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">坐标 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" id="lat" name="data[lat]"
                                           value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">银行名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[yh_zhihang]"
                                           value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">银行账号 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[yh_zhanghao]"
                                           value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <input type="submit" class="j-submit am-btn am-btn-secondary" name="subd" value="提交" />
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {

        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();

    });
    function regionSelect(obj,type){
        var val = $(obj).val();
        if(val >0){
            $("#lng").val($(obj).find("option:selected").attr("lng"));
            $("#lat").val($(obj).find("option:selected").attr("lat"));
            if(type == "city"){
                $("#city").html("");
                $("#district").html("");
            }
            var url = "<?=url('ajaxRegion')?>";
            $.ajax({
                url:url,
                data: {id:val},
                success:function (data) {

                    delProvince(data.data,type)
                }
            });
        }

    }

    function delProvince(data,type) {
        if(data && type){
            $("#"+type).html("");
            var htmlVal = "<option value=''></option>";
            $.each(data,function (i,val) {
                htmlVal += "<option value='"+val.id+"' lng='"+val.lng+"' lat='"+val.lat+"'>"+val.name+"</option>"
            });
            $("#"+type).html(htmlVal);
        }
    }
</script>
